package io.nmn.examples.sql2o;

import static spark.Spark.get;
import io.nmn.cloumbus.matrix.domain.MyMessage;
import io.nmn.cloumbus.util.JsonTransformer;
import io.nmn.examples.domain.Article;
import io.nmn.examples.domain.DbTest;
import io.nmn.examples.domain.GameInfo;

import java.util.HashMap;
import java.util.Map;
import java.util.List;




import org.sql2o.Query;
import org.sql2o.Sql2o;

import spark.ModelAndView;
import spark.template.freemarker.FreeMarkerEngine;




public class Sql2oTemplateDao {
	
	private static Sql2o sql2o = new Sql2o(
			"jdbc:jtds:sqlserver://192.168.60.51:51051/Ultima_Sample",
			"cji_netmarble_webacc", "sptakqmf111");

	
	public static DbTest getTasks() {
		String sql = "SELECT seq,name,price,[description]" + "FROM product "
				+ "where seq = :seq ";
		return sql2o.createQuery(sql).addParameter("seq", 1).executeAndFetchFirst(DbTest.class);
	}
	
	public static List<DbTest> getAllTasks() {
		String sql = "SELECT seq,name,price,[description]" + "FROM product "
				+ "where seq < :seq ";

		return sql2o.createQuery(sql).addParameter("seq", 1887).executeAndFetch(DbTest.class);
	}
	
	public static GameInfo getExecTasks() {
		String sql = "EXEC USP_GameInfoSelectList "
				+ " @gameSeq = :seq ";

		return sql2o.createQuery(sql).addParameter("seq", 1).executeAndFetchFirst(GameInfo.class);
	}
	
	public static Query getExecMapTasks() {
		String sql = "EXEC USP_GameInfoSelectList "
				+ " @gameSeq = :seq ";

		return sql2o.createQuery(sql).addParameter("seq", 1);
	}
	/*
	public static List<HashMap<String, Object>> getExecMapOutTasks() {
		String sql = "call USP_API_SAMPLE_OUT "
				+ " @I_SEQ = :seq "
				+ " ,@O_PRICE = :price "
				+ " ,@O_DESCRIPTION = :desc ";
		
		Query query = sql2o.createQuery(sql);
		
		query.addParameter("seq", 1);
		query.addParameter(":price", 1);
		query.addParameter(":desc", "1");
		return sql2o.createQuery(sql).addParameter("seq", 1).addParameter(":price", 1).addParameter(":desc", "1").executeAndFetchMap();
	}
	*/

}
